home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmiter.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  1.5 KB  |  55 lines

  1. // CmIter.cpp
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Abstract container iterator implementation.
  7. // -----------------------------------------------------------------
  8.  
  9. #include <cm/include/cmiter.h>
  10.  
  11. // "nextOccurence" advances the iterator to the next occurrence of
  12. // the specified object.
  13. //
  14. CmObject* CmIterator::nextOccurrence(CmObject* pObj)
  15. {
  16.   while (!done() && !(current()->isEqual(pObj))) next();
  17.   CmObject *out = (done()) ? NULL : current(); next();
  18.   if (out)
  19.     while (!done() && !(current()->isEqual(out)))
  20.       next();
  21.   return out;
  22. }
  23.  
  24.  
  25. // "previousOccurence" advances the iterator to the previous occurrence of
  26. // the specified object.
  27. //
  28. CmObject* CmIterator::previousOccurrence(CmObject* pObj)
  29. {
  30.   while (!done() && !(current()->isEqual(pObj))) previous();
  31.   CmObject *out = (done()) ? NULL : current(); previous();
  32.   if (out)
  33.     while (!done() && !(current()->isEqual(out)))
  34.       previous();
  35.   return out;
  36. }
  37.  
  38.  
  39. // "+=" advances the iterator n places and returns the object.
  40. //
  41. CmObject* CmIterator::operator+=(int num)
  42. {
  43.   for (int ii = 0; ii < num; ii++) next();
  44.   return current();
  45. }
  46.  
  47.  
  48. // "-=" decrements the iterator n places and returns the object.
  49. //
  50. CmObject* CmIterator::operator-=(int num)
  51. {
  52.   for (int ii = 0; ii < num; ii++) previous();
  53.   return current();
  54. }
  55.